package com.jc.service.api.yx163.product;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jc.cds.model.CustomSupplierGoods;
import com.jc.common.util.CheckNullUtils;
import com.jc.common.util.HtmlUtil;
import com.jc.ds.base.service.BaseServiceException;
import com.jc.ds.mapper.SupplierGoodsMapper;
import com.jc.ds.mapper.SupplierProductMapper;
import com.jc.ds.model.*;
import com.jc.framework.enums.*;
import com.jc.service.api.yx163.YanXuanAdapter;
import com.jc.service.attribute.AttributeService;
import com.jc.service.attributevalue.AttributeValueService;
import com.jc.service.h5.ShopService;
import com.jc.service.model.yx.*;
import com.jc.service.productattribute.ProAttributeService;
import com.jc.service.productattribute.ProductAttributeService;
import com.jc.service.producttype.ProductTypeService;
import com.jc.service.supplier.SupplierService;
import com.jc.service.suppliergoods.SupplierGoodsService;
import com.jc.service.suppliergoodspicturelist.SupplierGoodsPictureListService;
import com.jc.service.supplierproduct.SupplierProductService;
import com.jc.service.supplierproductprice.SupplierProductPriceService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;

import static com.alibaba.fastjson.JSON.parseObject;


@Service
public class ProductServiceImpl extends YanXuanAdapter implements ProductService {

    private final Logger LOGGER = LoggerFactory.getLogger(ProductServiceImpl.class);


    @Autowired
    private SupplierGoodsMapper supplierGoodsMapper;
    @Autowired
    private SupplierProductMapper supplierProductMapper;

    @Autowired
    private ProAttributeService proAttributeService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private ProductTypeService productTypeService;

    @Autowired
    SupplierService supplierService;

    @Autowired
    SupplierGoodsService supplierGoodsService;

    @Autowired
    SupplierProductService supplierProductService;

    @Autowired
    SupplierGoodsPictureListService supplierGoodsPictureListService;

    @Autowired
    SupplierProductPriceService supplierProductPriceService;

    @Autowired
    private AttributeValueService attributeValueService;

    @Autowired
    private ProductAttributeService productAttributeService;

    @Transactional
    public void getProductList() {
        LinkedHashMap<String, Object> _map = new LinkedHashMap<String, Object>();
        _map.put("method", YanXuanServiceName.YX_PRODUCT_QUERY.getName());
        _map.put("logType", LogType.GET163PRODUCT);//用于记录日志
        LinkedHashMap<String, Object> _params = getSign(_map);
        YanXuanResult result = postYanXuan(_params);
        if (result == null) {
            return;
        }
        if (StringUtils.isBlank(result.getCode()) || !StringUtils.equals("200", result.getCode())) {
            LOGGER.error("从网易获取商品列表错误, " + result.getMessage());
            return;
        }
        List<Object> resultList = (List<Object>) result.getResult();

        for (Object id : resultList) {
            LinkedHashMap<String, Object> _map2 = new LinkedHashMap<String, Object>();
            _map2.put("method", YanXuanServiceName.YX_PRODUCT_INFO_QUERY.getName());
            _map2.put("itemIds", String.valueOf(id));
            _map2.put("logType", LogType.GET163PRODUCTINFO);//用于记录日志
            LinkedHashMap<String, Object> queryProductParams = getSign(_map2);

            YanXuanResult result2 = postYanXuan(queryProductParams);
            List<Object> resultProductInfos = null;
            if (result2 != null && StringUtils.equals("200", result2.getCode())) {
                resultProductInfos = (List<Object>) result2.getResult();
            } else {
                LOGGER.error("从网易获取商品详情错误, " + "产品ID:" + _map2.get("itemIds") + ",  " + result.getMessage());
                continue;
            }

            for (Object o : resultProductInfos) {
                APIItemTO sp = parseObject(JSONObject.toJSONString(o), new TypeReference<APIItemTO>() {
                });
                SupplierGoods sug = packgeSupplierGoods(sp);

                //
                SupplierGoods _hasSupplierGoods = new SupplierGoods();
                _hasSupplierGoods.setSupplierGoodsId(sug.getSupplierGoodsId());
                _hasSupplierGoods.setSupplierId(sug.getSupplierId());
                List<SupplierGoods> _hasSupplierGoodsList = supplierGoodsService.queryAll(_hasSupplierGoods);
                Long _gid = 0l;

                if (CollectionUtils.isEmpty(_hasSupplierGoodsList)) {


                    supplierGoodsService.add(sug, false);
                    _gid = sug.getId();

                    //保存图片(轮播，详情)
                    List<SupplierGoodsPictureList> piclist = packgeSupplierGoodsPictureList(sp, sug.getId());
                    for (SupplierGoodsPictureList pic : piclist) {
                        supplierGoodsPictureListService.add(pic, false);
                    }
                } else {
                    _gid = _hasSupplierGoodsList.get(0).getId();
                }


                /***************************************************************************************************/
                List<SupplierProduct> productList = packgeYanXuanProduct(sp);
                JSONArray attrObjectArray = null;
                for (SupplierProduct spvo : productList) {

                    SupplierProduct _hasSupplierProduct = new SupplierProduct();
                    _hasSupplierProduct.setGid(_gid);
                    _hasSupplierProduct.setProductId(spvo.getProductId());

                    List<SupplierProduct> _hasSupplierProductList = supplierProductService.queryAll(_hasSupplierProduct);
                    if (CollectionUtils.isEmpty(_hasSupplierProductList)) {
                        spvo.setGid(sug.getId());
                        supplierProductService.add(spvo, false);
                        //checkProType(sug.getCategoryName(), spvo.getId(), Long.valueOf(spvo.getProductId()));
                        //checkProAttributeValue(attributeName, attributeValueName, productId, pid);
                        SupplierProductPrice price = getSupplierProductPrice(spvo.getId(), spvo.getProductId(), sp);
                        if (price != null) {
                            supplierProductPriceService.add(price, false);
                        }

                        //更新GOODS表中的规格字符串,
                        String attrString = spvo.getSpecificationsString();
                        attrObjectArray = JSONArray.parseArray(attrString);
                    }
                }


                List<Map<String, Object>> spceMapList = new ArrayList<Map<String, Object>>();
                for (int i = 0; attrObjectArray != null && i < attrObjectArray.size(); i++) {
                    JSONObject attrObject = attrObjectArray.getJSONObject(i);
                    Map<String, Object> map = new HashMap<String, Object>();
                    String _name = attrObject.getString("specHeader");
                    map.put("name", _name);
                    spceMapList.add(map);
                }
                if (CollectionUtils.isNotEmpty(spceMapList)) {
                    SupplierGoods updateSupplierGoods = new SupplierGoods();
                    updateSupplierGoods.setId(_gid);
                    updateSupplierGoods.setSpecificationsString(JSONObject.toJSONString(spceMapList));
                    supplierGoodsService.modify(updateSupplierGoods, false);
                }


            }

        }
    }

    public SupplierProductPrice getSupplierProductPrice(Long productId, String supplierSkuId, APIItemTO o) {

        List<APISkuTO> list = o.getSkuList();
        for (APISkuTO p : list) {
            BigDecimal salePrice = p.getChannelPrice();
            salePrice = salePrice.multiply(new BigDecimal(100));
            Long _skuId = p.getId();
            if (salePrice != null) {//转化以分为单位
                salePrice = salePrice.multiply(new BigDecimal(100));
            }
            if (salePrice.compareTo(new BigDecimal(0)) == 0) {
                return null;
            }
            if (StringUtils.equals(String.valueOf(_skuId), supplierSkuId)) {
                //暂时全渠道不收物流费
                int salePriceInt = 0;
                int costPriceInt = 0;
                if (salePrice != null) {
                    salePriceInt = salePrice.intValue();
                    double dl = 0.85;//网易严选 给我们的供货价格85折后为成本价
                    costPriceInt = (int) (salePriceInt * dl);
                }
                return getPrice(productId, salePriceInt, costPriceInt, 0);
            }
        }

        return null;
    }


    public List<SupplierGoodsPictureList> packgeSupplierGoodsPictureList(APIItemTO o, Long gid) {
        if (o == null) return null;
        if (o.getItemDetail() == null) {
            return null;
        }
        List<SupplierGoodsPictureList> retList = new ArrayList<SupplierGoodsPictureList>();
        String goodsDescHtml = o.getItemDetail().getDetailHtml();
        if (StringUtils.isNotBlank(goodsDescHtml)) {
            List<String> piclist = HtmlUtil.getImageSrc(goodsDescHtml);
            for (int i = 0; piclist != null && i < piclist.size(); i++) {
                String imgUrl = piclist.get(i);
                SupplierGoodsPictureList sgpl = new SupplierGoodsPictureList();
                sgpl.setGid(gid);
                sgpl.setImagePath(imgUrl);
                sgpl.setImageType(ImageType.DETAILS.getName());
                sgpl.setImageOrder(i);
                sgpl.setGoodsId(String.valueOf(o.getId()));
                retList.add(sgpl);
            }
        }
        //轮播图
        if (StringUtils.isNotBlank(o.getItemDetail().getPicUrl1())) {
            SupplierGoodsPictureList sgpl = new SupplierGoodsPictureList();
            sgpl.setGid(gid);
            sgpl.setImagePath(o.getItemDetail().getPicUrl1());
            sgpl.setImageType(ImageType.ROTATION.getName());
            sgpl.setImageOrder(0);
            sgpl.setGoodsId(String.valueOf(o.getId()));
            retList.add(sgpl);
        }

        if (StringUtils.isNotBlank(o.getItemDetail().getPicUrl2())) {
            SupplierGoodsPictureList sgpl = new SupplierGoodsPictureList();
            sgpl.setGid(gid);
            sgpl.setImagePath(o.getItemDetail().getPicUrl2());
            sgpl.setImageType(ImageType.ROTATION.getName());
            sgpl.setImageOrder(0);
            sgpl.setGoodsId(String.valueOf(o.getId()));
            retList.add(sgpl);
        }

        if (StringUtils.isNotBlank(o.getItemDetail().getPicUrl3())) {
            SupplierGoodsPictureList sgpl = new SupplierGoodsPictureList();
            sgpl.setGid(gid);
            sgpl.setImagePath(o.getItemDetail().getPicUrl3());
            sgpl.setImageType(ImageType.ROTATION.getName());
            sgpl.setImageOrder(0);
            sgpl.setGoodsId(String.valueOf(o.getId()));
            retList.add(sgpl);
        }
        if (StringUtils.isNotBlank(o.getItemDetail().getPicUrl4())) {
            SupplierGoodsPictureList sgpl = new SupplierGoodsPictureList();
            sgpl.setGid(gid);
            sgpl.setImagePath(o.getItemDetail().getPicUrl4());
            sgpl.setImageType(ImageType.ROTATION.getName());
            sgpl.setImageOrder(0);
            sgpl.setGoodsId(String.valueOf(o.getId()));
            retList.add(sgpl);
        }

        return retList;
    }

    public List<SupplierProduct> packgeYanXuanProduct(APIItemTO o) {
        if (o == null) throw new BaseServiceException("对象为空,无法转换为supplierProduct");
        List<APISkuTO> skuList = o.getSkuList();
        List<SupplierProduct> productList = new ArrayList<SupplierProduct>();
        SupplierProduct sp;
        for (APISkuTO sku : skuList) {
            sp = new SupplierProduct();
            sp.setProductId(String.valueOf(sku.getId()));
            sp.setProductName(o.getName());
            sp.setProductInventoryId("0"); //网易产品信息不包含库存，需要单独请求查询库存接口刷新库存
            sp.setProductImagePath(sku.getPicUrl());//规格产品图片
            sp.setSelfProductImagePath("");
            sp.setBarCode("");
            sp.setHastax(HasTax.HASTAX.getName());//默认全部含税,因为严选发货，开票
            sp.setGoodsId(String.valueOf(o.getId()));
            sp.setPushStatus(Push.WAIT_DEAL.getName());
            sp.setIsImgCompression(SupplierImageZipStatus.UNZIP.getName());
            sp.setInventoryNum(0);
            sp.setInventoryId("0");
            sp.setStoreId("");//严选渠道无法获取，严选后面实际的供应商，这里不填
            sp.setIsPerfect("N");
            List<APIItemSkuSpecValueTO> specList = sku.getItemSkuSpecValueList();
            //##组装SKU的属性字符串
            List<Map<String, Object>> spceMapList = new ArrayList<Map<String, Object>>();
            for (APIItemSkuSpecValueTO spc : specList) {
                Map<String, Object> map = new HashMap<String, Object>();
                APISkuSpecTO spceObject = spc.getSkuSpec();
                if (spceObject != null && StringUtils.isNotBlank(spceObject.getName())) {
                    map.put("specHeader", spceObject.getName());
                }
                APISkuSpecValueTO spceObjectValue = spc.getSkuSpecValue();
                if (spceObjectValue != null && StringUtils.isNotBlank(spceObjectValue.getValue())) {
                    map.put("detailName", spceObjectValue.getValue());
                    map.put("specificationDetailId", spceObjectValue.getId());
                }
                spceMapList.add(map);
            }
            if (CollectionUtils.isNotEmpty(spceMapList)) {
                sp.setSpecificationsString(JSONObject.toJSONString(spceMapList));
            }
            productList.add(sp);
        }
        return productList;
    }


    public SupplierGoods packgeSupplierGoods(APIItemTO o) {
        if (o == null) throw new BaseServiceException("对象为空,无法转换为supplierGoods");
        SupplierGoods supplierGoods = new SupplierGoods();
        String supplierName = "网易严选";
        Supplier _sper = new Supplier();
        _sper.setFullName(supplierName);
        _sper.setIsDelete(Booleans.FALSE.getName());
        List<Supplier> _sperlist = supplierService.queryAll(_sper);
        if (CollectionUtils.isEmpty(_sperlist)) {
            throw new BaseServiceException(supplierName + "错误，此供应商不存在,请先完善供应商信息");
        }
        if (_sperlist.size() > 1) {
            throw new BaseServiceException(supplierName + "错误，这个供应商名称在供应商表中存在两条同名供应商");
        }
        String supplierId = _sperlist.get(0).getSupplierSn();
        supplierGoods.setSupplierId(Integer.parseInt(supplierId));
        supplierGoods.setSupplierName(supplierName);
        supplierGoods.setName(o.getName());
        //supplierGoods.setBrandid();
        supplierGoods.setBrandnamecn(supplierName);
        supplierGoods.setCreateTime(new Date());
        supplierGoods.setLastUpdateTime(new Date());
        //supplierGoods.setBrandnameen();
        //分类
        List<List<APICategoryPathTO>> typelist = o.getCategoryPathList();
        APICategoryPathTO category3 = getCategoryName(typelist, 1);
        APICategoryPathTO category2 = getCategoryName(typelist, 2);
        if (category3 != null) {
            //supplierGoods.setCategoryId(Integer.parseInt(category3.getId()));
            supplierGoods.setCategoryName(category3.getName());
        }
        if (category2 != null) {
            supplierGoods.setCategoryParentName(category2.getName());
        }
        //LOGGER.error("网易分类3: " + category3.getName());
        supplierGoods.setGoodsDesc(o.getItemDetail().getDetailHtml());
        supplierGoods.setGoodsDescType(GoodsDescType.PIC.getName());
        supplierGoods.setSupplierGoodsId(String.valueOf(o.getId())); //严选SPU ID
        supplierGoods.setCreateTime(new Date());
        supplierGoods.setGoodNatureType(GoodNatureType.MATERIAL.getName());
        //拼接当前 产品推送商城接口的 规格字符串,这个字符串是当前版本推送商城需要用的，后面这个字段会弃用，

        List<APIItemAttributeTO> goodsAttrList = o.getAttrList();
        List<Attr> attrList = new ArrayList<Attr>();
        List<AttrValue> attrValueList = new ArrayList<AttrValue>();
        //LOGGER.error("网易严选规格字符串 : : " + JSONObject.toJSONString(goodsAttrList));
        for (APIItemAttributeTO spc : goodsAttrList) {
            Attr attr = new Attr();
            attr.setName(spc.getAttrName());
            attr.setSpecificationId("");
            AttrValue atr = new AttrValue();
            atr.setDetailName(spc.getAttrValue());
            atr.setSpecificationDetailId("");
            atr.setSpecificationDetailImage("");
            attrValueList.add(atr);
            attr.setValue(attrValueList);

            attrList.add(attr);
        }
        supplierGoods.setSpecificationsString(JSONObject.toJSONString(attrList));


        //循环不发货地区
        //o.getItemDetail().getDeliveryAreaList()
        //APIItemDeliveryAreaTO

        if (o.getItemDetail() != null && o.getItemDetail().getDeliveryAreaList() != null) {
            String sendAreaListFix = "";
            APIItemDeliveryAreaTO itemDelivery = o.getItemDetail().getDeliveryAreaList();
            if (itemDelivery.getSupportStatus() != null && itemDelivery.getSupportStatus() == 1) {
                sendAreaListFix = "不支持配送以下地区 : ";
            } else if (itemDelivery.getSupportStatus() != null && itemDelivery.getSupportStatus() == 2) {
                sendAreaListFix = "只支持配送以下地区 : ";
            }

            String sendAreaList = "";
            List<APIItemDistrictSupportTO> areaList = itemDelivery.getSupportedDistricts();
            for (APIItemDistrictSupportTO area : areaList) {
                if (area.getAreaType() != null && area.getAreaType() == 0) {//只判断国内区域
                    sendAreaList = sendAreaList + area.getProvinceName() + ",";
                }
            }

            if (StringUtils.isNotBlank(sendAreaList)) {
                sendAreaList = sendAreaList.substring(0, sendAreaList.length() - 1);
                supplierGoods.setSupplierRemark(sendAreaListFix + sendAreaList);
            }


        }
        return supplierGoods;
    }

    /***
     *
     * @Title: getCategoryName
     * @Description: TODO
     * @param @param deep 深度  1 , 取最未级分类, 2 取次末级分类,若LIST只有一级分类，则，次，末级分类名称一样.
     * @param @return
     * @return String
     * @throws
     */
    public APICategoryPathTO getCategoryName(List<List<APICategoryPathTO>> typelist, int deep) {

        if (typelist == null || typelist.size() < 1) return null;
        //我们目前一种产品只支持一种最小分类,所以只取一种分类
        List<APICategoryPathTO> list = typelist.get(0);
        Collections.reverse(list);
        if (list != null && list.size() > 0) {
            if (deep == 1) return list.get(0);
            if (deep == 2) {
                if (list.size() > 1 && list.get(1) != null) {
                    return list.get(1);
                } else {
                    if (list.get(0) != null) return list.get(0);
                }
            }
        }
        return null;
    }

    /**
     * 查询展示商品
     */
    @Override
    public Map<String, Object> queryProduct(Map<String, Object> params) {

        String productName = String.valueOf(params.get("productName"));
        String productId = String.valueOf(params.get("productId"));
        String supplierName = String.valueOf(params.get("supplierName"));
        String supplierId = String.valueOf(params.get("supplierId"));
        String pushStatus = String.valueOf(params.get("pushStatus"));

        SupplierGoods supplierGoods = new SupplierGoods();
        Supplier supplier = new Supplier();
        SupplierProduct supplierProduct = new SupplierProduct();
        SupplierGoodsPictureList supplierGoodsPictureList = new SupplierGoodsPictureList();
        SupplierProductPrice supplierProductPrice = new SupplierProductPrice();

        List<Supplier> suppliers = new ArrayList<>();
        List<SupplierGoods> supplierGoodss = new ArrayList<>();
        List<SupplierProduct> supplierProducts = new ArrayList<>();
        //商品名字
        if (!"null".equals(productName) && productName != null && !"".equals(productName)) {
            supplierGoods.setName(productName);
            supplierProduct.setProductName(productName);
        }
        //商品编码
        if (!"null".equals(productId) && productId != null && !"".equals(productId)) {
            supplierProduct.setGoodsId(productId);
        }
        //供应商名字
        if (!"null".equals(supplierName) && supplierName != null && !"".equals(supplierName)) {
            supplier.setFullName(supplierName);
        }
        //供应商编码
        if (!"null".equals(supplierId) && supplierId != null && !"".equals(supplierId)) {
            supplier.setSupplierSn(supplierId);
        }
        //推送状态
        if (!"null".equals(pushStatus) && pushStatus != null && !"".equals(pushStatus)) {
            supplierProduct.setPushStatus(Integer.valueOf(pushStatus));
        }

        Map<String, Object> alls = new HashMap<>();
        alls.put("supplierGoodss", supplierGoodss);
        alls.put("suppliers", suppliers);
        alls.put("supplierProducts", supplierProducts);

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("data", alls);
        resultMap.put("code", "10000");

        return resultMap;
    }

    /**
     * 所有商品
     */
    @Override
    public Map<String, Object> queryAllProduct() {
        Map<String, Object> result = new HashMap<>();


        List<Supplier> suppliers = this.supplierService.queryAll(new Supplier());
        List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(new SupplierProduct());
        List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryAll(new SupplierGoods());
        List<SupplierProductPrice> supplierProductPrices = this.supplierProductPriceService.queryAll(new SupplierProductPrice());
        List<SupplierGoodsPictureList> supplierGoodsPictureListLists = this.supplierGoodsPictureListService.queryAll(new SupplierGoodsPictureList());

        result.put("suppliers", suppliers);
        result.put("supplierProducts", supplierProducts);
        result.put("supplierGoods", supplierGoods);
        result.put("supplierProductPrices", supplierProductPrices);
        result.put("supplierGoodsPictureListLists", supplierGoodsPictureListLists);


        return result;
    }

    /***
     * //根据spu主键查询sku
     */
    @Override
    public Map<String, Object> querySupplierProduct(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> result111 = new HashMap<>();
        String id = String.valueOf(params.get("id"));
        if (!"null".equals(id) && id != null && !"".equals(id)) {
            SupplierProduct supplierProduct = new SupplierProduct() {{
                setGid(Long.valueOf(id));
            }};

            List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryAll(new SupplierGoods() {{
                setId(Long.valueOf(id));
            }});


            ArrayList<Object> speList = new ArrayList<>();
            //规格参数 解析 key:value 返回给前台
            for (SupplierGoods supplierGoods1 : supplierGoods) {
                List list = (List) JSONObject.parse(supplierGoods1.getSpecificationsString());
                for (Object o : list) {
                    Map<String, Object> map = JSONObject.parseObject(String.valueOf(o));
                    // List<Map<String, Object>> values = (List<Map<String, Object>>) map.get("value");
                    String value1 = String.valueOf(map.get("value"));
                    System.out.println("value1 = " + value1);
                    List list2 = (List) JSONObject.parse(value1);
                    for (Object o1 : list2) {
                        Map<String, Object> value = JSONObject.parseObject(String.valueOf(o1));
                        Set<String> strings = value.keySet();//key
                        for (String string : strings) {
                            String valuess = String.valueOf(value.get(string));//value
                            result111.put("selectOne", string);
                            result111.put("selectTwo", valuess);
                            speList.add(result111);
                            result.put("speMap", speList);
                        }
                    }
                }
                supplierGoods1.setSpecificationsString(pullSpeString(supplierGoods1.getSpecificationsString()));
                result.put("supplierGoods", supplierGoods1);
                result.put("goodsId", supplierGoods1.getBrandid());
                if (supplierGoods1.getGoodsDesc().equals("PIC")) {
                    int goodsType = 1;
                    result.put("goodsType", goodsType);
                } else {
                    int goodsType = 2;
                    result.put("goodsType", goodsType);
                }
                String specificationsString = supplierGoods1.getSpecificationsString();


            }

            ArrayList<Object> objects1 = new ArrayList<>();
            List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(supplierProduct);
            supplierProducts.forEach((supplierProduct1) -> {
                if (supplierProduct1.getPushStatus() == 0) {
                    supplierProduct1.setExtend5("不推送");
                }
                if (supplierProduct1.getPushStatus() == 1) {
                    supplierProduct1.setExtend5("待推送");
                }
                if (supplierProduct1.getPushStatus() == 2) {
                    supplierProduct1.setExtend5("已推送");
                }
                if (supplierProduct1.getPushStatus() == 3) {
                    supplierProduct1.setExtend5("推送失败");
                }
                objects1.add(supplierProduct1);

            });
            result.put("supplierProducts", objects1);
            ArrayList<Object> objects2 = new ArrayList<>();

            for (SupplierProduct product : supplierProducts) {
                SupplierProductPrice supplierProductPrice = new SupplierProductPrice() {{
                    setSupplierProductId(product.getId());
                }};
                Map<String, Object> stringObjectHashMap1 = new HashMap<>();
                List<SupplierProductPrice> supplierProductPrices = this.supplierProductPriceService.queryAll(supplierProductPrice);
                supplierProductPrices.forEach((supplierProductPrice1) -> {
                            stringObjectHashMap1.put("supplierProductPrices", supplierProductPrice1);
                            stringObjectHashMap1.put("inPrice", Double.valueOf(supplierProductPrice1.getCooperateprice() / 100.0));
                            stringObjectHashMap1.put("outPrice", Double.valueOf(supplierProductPrice1.getSaleprice() / 100.0));

                        }
                );
                objects2.add(stringObjectHashMap1);
            }
            result.put("supplierProductPrices", objects2);
            SupplierGoodsPictureList supplierGoodsPictureList = new SupplierGoodsPictureList() {{
                setGid(Long.valueOf(id));
            }};
            ArrayList<Object> objects = new ArrayList<>();
            List<SupplierGoodsPictureList> supplierGoodsPictureListList = this.supplierGoodsPictureListService.queryAll(supplierGoodsPictureList);
            int i = 0;
            for (SupplierGoodsPictureList supplierGoodsPictureList1 : supplierGoodsPictureListList) {
                Map<String, Object> stringObjectHashMap = new HashMap<>();
                stringObjectHashMap.put("id", i);
                stringObjectHashMap.put("picList", supplierGoodsPictureList1.getImagePath());
                stringObjectHashMap.put("picType", supplierGoodsPictureList1.getImageType());
                objects.add(stringObjectHashMap);
                i++;
            }


            result.put("supplierGoodsPictureListList", objects);


            result.put("pics", supplierGoodsPictureListList);
        } else {
            result.put("msg", "id不存在~~");
            result.put("code", "4000");
        }
        return result;
    }


    @Autowired
    private PushUtils pushUtils;


    /**
     * 点击推送商品
     */
    @Override
    public Map<String, Object> clickPushGoods(Map<String, Object> params) {
        String id = String.valueOf(params.get("id"));
        Map<String, Object> result = new HashMap<>();
        //根据id推送商品
        if (!CheckNullUtils.isNull(id)) {

            SupplierGoods supplierGoods = this.supplierGoodsService.queryById(Long.valueOf(id));
            CustomSupplierGoods goods = new CustomSupplierGoods();
            BeanUtils.copyProperties(supplierGoods, goods);

            try {
                String s = pushUtils.pushGoods(goods);
                if ("0".equals(s)) {
                    result.put("msg", "推送成功~~");
                    result.put("code", "10000");
                } else {
                    result.put("msg", "推送失败~~");
                    result.put("code", "10000");
                }


            } catch (Exception e) {
                result.put("msg", "推送失败！");
                result.put("code", "4000~~");
                e.printStackTrace();
            }
        }
        return result;
    }

    /***
     * 根据供应商查询spu
     * */

    @Override
    public Map<String, Object> queryProductBySupplier(Map<String, Object> params) {

        String supplier = String.valueOf(params.get("supplier"));

          String listName = String.valueOf(params.get("listName"));

        String selectNameOne = String.valueOf(params.get("selectNameOne"));


        Map<String, Object> result = new HashMap<>();

        SupplierGoods supplierGoods1 = new SupplierGoods();
        if (!CheckNullUtils.isNull(supplier)) {
            supplierGoods1.setSupplierName(supplier);
        }
        if (!CheckNullUtils.isNull(listName)) {
            supplierGoods1.setCategoryParentName(listName);
        }

        if (!CheckNullUtils.isNull(selectNameOne)) {
            supplierGoods1.setName(selectNameOne);
        }
        Page<Object> objects = PageHelper.startPage(Integer.valueOf(params.get("start").toString()), Integer.valueOf(params.get("limit").toString()));


        List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryLikeAll(supplierGoods1);

        int count = this.supplierGoodsService.queryLikeAllCount(supplierGoods1);
      /*  for (SupplierGoods supplierGood : supplierGoods) {
            count++;

            List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(new SupplierProduct() {{
                setGid(supplierGood.getId());
                //  setProductName(supplierGood.getName());
            }});
            supplierProducts.forEach((supplierProduct) -> {
                if (supplierProduct.getPushStatus() == 1) {
                    supplierGood.setExtend5("待推送");
                }
                if (supplierProduct.getPushStatus() == 2) {
                    supplierGood.setExtend5("推送成功");
                }
                if (supplierProduct.getPushStatus() == 3) {
                    supplierGood.setExtend5("推送失败");
                }
                if (supplierProduct.getPushStatus() == 0) {
                    supplierGood.setExtend5("不推送");
                }
            });
        }*/
        if (CollectionUtils.isNotEmpty(supplierGoods)) {
            result.put("data", supplierGoods);
            result.put("code", "10000");
            result.put("count", count);

        } else {
            result.put("msg", "没有数据");
            result.put("code", "4000");
        }


        return result;
    }

    /***
     * 根据spu主键删除
     * */

    @Transactional
    @Override
    public Map<String, Object> deleteProductById(Map<String, Object> params) {

        Map<String, Object> result = new HashMap<>();
        if (CheckNullUtils.isNull(String.valueOf(params.get("id")))) {
            result.put("msg", "删除失败,您并没有选中任何");
            result.put("code", "5000");
            return result;
        }
        String id = String.valueOf(params.get("id"));

        int a = 0;
        int b = 0;
        int c = 0;
        int d = 0;
        int e = 0;

        if (!CheckNullUtils.isNull(id)) {
            SupplierProduct supplierProduct = new SupplierProduct() {{
                setGid(Long.valueOf(id));
            }};
            //删除图片
            List<SupplierGoodsPictureList> supplierGoodsPictureListList = this.supplierGoodsPictureListService.queryAll(new SupplierGoodsPictureList() {{
                setGid(Long.valueOf(id));
            }});
            for (SupplierGoodsPictureList supplierGoodsPictureList : supplierGoodsPictureListList) {
                a = this.supplierGoodsPictureListService.remove(supplierGoodsPictureList.getId());
            }
            //删除价格
            List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(supplierProduct);
            for (SupplierProduct product : supplierProducts) {
                SupplierProductPrice supplierProductPrice = new SupplierProductPrice();
                supplierProductPrice.setSupplierProductId(product.getId());
                List<SupplierProductPrice> supplierProductPrices = this.supplierProductPriceService.queryAll(supplierProductPrice);
                for (SupplierProductPrice productPrice : supplierProductPrices) {
                    b = this.supplierProductPriceService.remove(productPrice.getId());
                }

                //删除规格
                e = this.productAttributeService.remove(product.getId());

            }


            //删除sku
            for (SupplierProduct product : supplierProducts) {
                c = this.supplierProductService.remove(product.getId());
            }

            //删除spu
            d = this.supplierGoodsService.remove(Long.valueOf(id));


            if (a == 1 && b == 1 && c == 1 && d == 1) {
                result.put("msg", "删除成功");
            }

        }
        return result;
    }

    /**
     * 所有的supplierGoods
     */
    @Override
    public Map<String, Object> queryALLSPU(Map<String, Object> map1) {
        Map<String, Object> result = new HashMap<>();
//        int count = 0;

//        List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryLikeAll(new SupplierGoods() {{
////            setName("");
////        }});
        Long start = Long.valueOf((String) map1.get("start"));
        Long limit = Long.valueOf((String) map1.get("limit"));
        if (start == 1L) {
            start = 0L;
        } else {
            start = limit * (start - 1);
        }

        List<SupplierGoods> lists = this.supplierGoodsMapper.queryByLimit(start, limit);
        for (SupplierGoods list : lists) {
            System.out.println(list.toString());
        }
        int count = supplierGoodsService.queryAllCount(new SupplierGoods());
//        for (SupplierGoods supplierGood : supplierGoods) {
//            count++;
//        }
        for (SupplierGoods supplierGood : lists) {
            List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(new SupplierProduct() {{
                setGid(supplierGood.getId());
                //  setProductName(supplierGood.getName());
            }});
            supplierProducts.forEach((supplierProduct) -> {
                if (supplierProduct.getPushStatus() == 1) {
                    supplierGood.setExtend5("待推送");
                }
                if (supplierProduct.getPushStatus() == 2) {
                    supplierGood.setExtend5("推送成功");
                }
                if (supplierProduct.getPushStatus() == 3) {
                    supplierGood.setExtend5("推送失败");
                }
                if (supplierProduct.getPushStatus() == 0) {
                    supplierGood.setExtend5("不推送");
                }
            });
        }
        if (CollectionUtils.isNotEmpty(lists)) {
            result.put("data", lists);
            result.put("code", "10000");
            result.put("count", count);

        } else {
            result.put("msg", "没有数据");
            result.put("code", "4000");
        }
        return result;
    }

    /**
     * 前台手动新增商品(修改)
     */
    @Transactional
    @Override
    public Map<String, Object> handAddProduct(Map<String, Object> params) {


        Map<String, Object> result = new HashMap<>();

        //修改的话 传入主键 根据主键删除产品  再新增
        String id = String.valueOf(params.get("id")); //产品主键id
        if (!CheckNullUtils.isNull(id)) {
            Map<String, Object> delMap = new HashMap<>();
            delMap.put("id", id);
            Map<String, Object> map = deleteProductById(delMap);
            if (!map.get("msg").equals("删除成功")) {
                result.put("msg", "更新失败！,亲刷新页面,~");
                result.put("code", "5000");
                return result;
            }
        }


        //开始新增
        int freight = 0; //运费默认0
        int addGoods = 0;
        int addProduct = 0;
        int addPrice = 0;
        int addPic = 0;
        //通用规格
        String name = String.valueOf(params.get("name")); //商品名字
        String brandNameCn = String.valueOf(params.get("brandNameCn")); //品牌中文名称
        String brandNameEn = String.valueOf(params.get("brandNameEn")); //品牌英文名称
        String supplierFullName = String.valueOf(params.get("supplierFullName")); //供应商全称
        //私有规格 数组
        String productId = String.valueOf(params.get("productId")); //产品id
        String goodsId = String.valueOf(params.get("goodsId")); //供应商产品编码
        String cooperatePrice = String.valueOf(params.get("cooperatePrice")); //进价
        String salePrice = String.valueOf(params.get("salePrice")); //售价
        String goodsDesc = String.valueOf(params.get("goodsDesc")); //产品文字详情
        String inventoryNum = String.valueOf(params.get("inventoryNum")); //库存数
        String goodsDescType = String.valueOf(params.get("goodsDescType")); //产品详情 todo 图片/文字
        String imageType = String.valueOf(params.get("imageType")); //产品详情 todo 轮播图和详情图
        String selectDataOne = String.valueOf(params.get("selectDataOne")); //产品详情 todo 规格一
        String selectDataTwo = String.valueOf(params.get("selectDataTwo")); //产品详情 todo 规格2
        String imageUrl = String.valueOf(params.get("imageUrl")); //产品详情 todo 规格2


        ArrayList<Object> objects1 = new ArrayList<>();
        Map<String, Object> speMap = new HashMap<>();
        speMap.put("name", "规格");
        ArrayList<Object> objects = new ArrayList<>();
        Map<String, Object> inMap = new HashMap<>();
        inMap.put(selectDataOne, selectDataTwo);
        objects.add(inMap);
        speMap.put("value", objects);
        objects1.add(speMap);
        String speString = JSONObject.toJSONString(objects1);


        //详情文字还是图片
        if (goodsDescType.equals("1")) {
            goodsDescType = "pic";
        } else {
            goodsDescType = "html";
        }
        //售价大于进价
        if (Long.valueOf(salePrice) < Long.valueOf(cooperatePrice)) {
            result.put("msg", "售价低于进价了~~~注意填写");
            result.put("code", "5000");
            return result;
        }

        String substring = imageUrl.substring(1, imageUrl.length() - 1);
        String[] imgSplit = substring.split(",");


        List<Supplier> suppliers = this.supplierService.queryAll(new Supplier() {{
            setFullName(supplierFullName);
        }});
        if (suppliers.size() == 0) {
            result.put("msg", "供应商没查到~~~~~");
            result.put("code", "5000");
            return result;
        }
        //判断skuid 不能冲突
        List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryAll(new SupplierGoods() {{
            setBrandid(Long.valueOf(productId));
            setSupplierName(supplierFullName);
        }});
        if (supplierGoods.size() > 0) {
            result.put("msg", "该供应商下面产品id已经存在！请先检查在保存~~~~~");
            result.put("code", "5000");
            return result;
        }


        for (Supplier supplier : suppliers) {
            //todo 保存supplierGoods
            String finalGoodsDescType = goodsDescType;
            addGoods = this.supplierGoodsService.add(new SupplierGoods() {{
                setSupplierId(Integer.valueOf(supplier.getSupplierSn()));
                setName(name);
                setBrandnamecn(brandNameCn);
                if (!"null".equals(brandNameEn)) {
                    setBrandnameen(brandNameEn);
                }
                setSupplierName(supplierFullName);
                setBrandid(Long.valueOf(productId));
                setGoodsDescType(finalGoodsDescType);
                setGoodsDesc(goodsDesc);
                setSupplierGoodsId(productId);
                setCreateTime(new Date());
                setLastUpdateTime(new Date());
                setGoodNatureType(1);
                setSpecificationsString(speString);

            }}, false);

        }
        List<SupplierGoods> supplierGoodsQuer = this.supplierGoodsService.queryAll(new SupplierGoods() {{
            setBrandid(Long.valueOf(productId));
            setName(name);
            setSupplierName(supplierFullName);
        }});

        // todo 保存supplierProduct
        for (SupplierGoods supplierGoods1 : supplierGoodsQuer) {
            addProduct = this.supplierProductService.add(new SupplierProduct() {{
                setGid(supplierGoods1.getId());
                setProductId(productId);
                setProductName(name);
                setHastax(0);
                setGoodsId(goodsId);
                setProductImagePath(imgSplit[0].substring(1, imgSplit[0].length() - 1));
                setPushStatus(1);
                setIsImgCompression(0);
                setInventoryNum(Integer.valueOf(inventoryNum));
                setIsPerfect("Y");
                setSpecificationsString(speString);
            }}, false);

            for (String s : imgSplit) {
                //todo 保存supplierProductPictureList
                //保存 轮播或者详情或者两者都是
                if (!imageType.equals("3")) {

                    addPic = this.supplierGoodsPictureListService.add(new SupplierGoodsPictureList() {{
                        setGid(supplierGoods1.getId());
                        setImagePath(s.substring(1, s.length() - 1));
                        setImageType(Integer.valueOf(imageType));
                        setWidth(200);
                        setHeight(200);
                        setImageOrder(0);
                        setGoodsId(supplierGoods1.getSupplierGoodsId());
                    }}, false);
                }
                if (imageType.equals("3")) {
                    addPic = this.supplierGoodsPictureListService.add(new SupplierGoodsPictureList() {{
                        setGid(supplierGoods1.getId());
                        setImagePath(s.substring(1, s.length() - 1));
                        setImageType(1);
                        setWidth(200);
                        setHeight(200);
                        setImageOrder(0);
                        setGoodsId(supplierGoods1.getSupplierGoodsId());
                    }}, false);
                    addPic = this.supplierGoodsPictureListService.add(new SupplierGoodsPictureList() {{
                        setGid(supplierGoods1.getId());
                        setImagePath(s.substring(1, s.length() - 1));
                        setImageType(2);
                        setWidth(200);
                        setHeight(200);
                        setImageOrder(0);
                        setGoodsId(supplierGoods1.getSupplierGoodsId());
                    }}, false);

                }
            }

        }

        List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(new SupplierProduct() {{
            setProductName(name);
            //   setGoodsId(goodsId);
            setProductId(productId);
        }});
        //todo 保存supplierProductPrice
        for (SupplierProduct supplierProduct : supplierProducts) {
            addPrice = this.supplierProductPriceService.add(new SupplierProductPrice() {
                {
                    int cooperatePriceF = getSavePrice(cooperatePrice);//进价换算
                    int salePriceF = getSavePrice(salePrice);//售价换算

                    setSupplierProductId(supplierProduct.getId());
                    setCooperateprice(cooperatePriceF);
                    setTaxcooperateprice(0);
                    setMoneyPrice(salePriceF);
                    setSaleprice(salePriceF);
                    // setSupplierProductId(Long.valueOf(productId));

                    //计算价格
                    int step = (salePriceF - cooperatePriceF) / 4; // 四个等级，每级的差价
                    int private_cost_price = cooperatePriceF + freight;
                    setMoneyPrice(salePriceF);
                    setLeve1Price(private_cost_price + step + step + step);
                    setLeve2Price(private_cost_price + step + step);
                    setLeve3Price(private_cost_price + step);
                    setLeve4Price(private_cost_price);
                    setCostPrice(private_cost_price);
                    setUnionCostPrice(private_cost_price);
                    setDefaultFreight(freight);
                }

            }, false);

        }


        if (addGoods == 1 && addPrice == 1 && addProduct == 1 && addPic == 1) {
            result.put("data", "保存好了~~");
            result.put("code", "10000");
        } else {
            result.put("msg", "保存失败~~~");
            result.put("code", "5000");
        }

        return result;
    }

    //计算价格*100
    private int getSavePrice(String priceCC) {
        int getSavePrice = 0;
        String price = String.valueOf(priceCC);
        if (price.contains(".")) {
            Double i = Double.valueOf(priceCC) * 100;
            getSavePrice = Integer.valueOf(String.valueOf(i).split("\\.")[0]);
        } else {
            getSavePrice = Integer.valueOf(priceCC) * 100;
        }
        return getSavePrice;
    }

    //分装特殊规格属性
    private String getSpeString() {


        return null;
    }

    //前台返回特殊属性
    private String pullSpeString(String str) {
        List<Map<String, Object>> list = (List<Map<String, Object>>) JSONObject.parse(str);

        ArrayList<String> strs = new ArrayList<>();
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder sb = new StringBuilder();

        String name = null;
        String s = null;
        int i = 0;
        for (Map<String, Object> map : list) {
            name = String.valueOf(map.get("name")); //规格参数名
            List<Map<String, Object>> values = (List<Map<String, Object>>) map.get("value"); //规格参数
            i = 0;
            for (Map<String, Object> value : values) {
                Collection<Object> values1 = value.values();
                Object valuess = values1.toArray()[i];
                Object keyss = value.keySet().toArray()[i];
                stringBuilder.append(" ").append(keyss).append(":").append(valuess);
            }
            s = stringBuilder.toString();

            String result = sb.append(name).append("-----").append(s).append("\t").toString();
            strs.add(result);
            sb.setLength(0);
            stringBuilder.setLength(0);

        }
        StringBuilder stringBuilder1 = new StringBuilder();
        for (String ss : strs) {
            stringBuilder1.append(ss).append("  ");
        }
        String sss = stringBuilder1.toString();
        return sss;
    }

    //封装相册
    //{
    //  "title": "", //相册标题
    //  "id": 123, //相册id
    //  "start": 0, //初始显示的图片序号，默认0
    //  "data": [   //相册包含的图片，数组格式
    //    {
    //      "alt": "图片名",
    //      "pid": 666, //图片id
    //      "src": "", //原图地址
    //      "thumb": "" //缩略图地址
    //    }
    //  ]
    //}
    private Map<String, Object> getPhonesString(List<SupplierGoodsPictureList> PicList) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("title", "详情图片");
        resultMap.put("id", "666");
        resultMap.put("start", "0");
        ArrayList<Map<String, Object>> maps = new ArrayList<>();
        for (SupplierGoodsPictureList supplierGoodsPictureList : PicList) {
            Map<String, Object> dataM = new HashMap<>();
            dataM.put("alt", supplierGoodsPictureList.getImagePath());
            dataM.put("pid", supplierGoodsPictureList.getId());
            dataM.put("src", supplierGoodsPictureList.getImagePath());
            dataM.put("thumb", supplierGoodsPictureList.getImagePath());
            maps.add(dataM);
        }
        resultMap.put("data", maps);
        return resultMap;
    }


    /**
     * 回显编辑产品固定格式
     */
    @Override
    public Map<String, Object> proEditShow(Map<String, Object> params) {

        Map<String, Object> result = new HashMap<>();

        String id = String.valueOf(params.get("id"));
        if (CheckNullUtils.isNull(id)) {
            result.put("code", "4000");
            result.put("msg", "没有接受到参数的id");
        }

        List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryAll(new SupplierGoods() {{
            setId(Long.valueOf(id));
        }});
        if (supplierGoods.size() > 1 || supplierGoods.size() == 0) {
            result.put("code", "4000");
            result.put("msg", "该产品id存在多个或者暂时无法编辑，亲稍后再试试~");
            return result;
        }

        Map<String, Object> comonListMap = new HashMap<>();
        Map<String, Object> speMap = new HashMap<>();

        String branNameEn = null;

        SupplierGoods supplierGood = supplierGoods.get(0);
        if (StringUtils.isEmpty(supplierGood.getBrandnameen())) {
            branNameEn = "";
        }
        comonListMap.put("name", supplierGood.getName());
        comonListMap.put("branNameCn", supplierGood.getBrandnamecn());
        comonListMap.put("branNameEn", branNameEn);
        comonListMap.put("supplierFullName", supplierGood.getSupplierName());

        //查询supplierProduct
        List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(new SupplierProduct() {{
            setGid(supplierGood.getId());
            setProductName(supplierGood.getName());
        }});
        if (supplierProducts.size() > 1 || supplierProducts.size() == 0) {
            result.put("code", "4000");
            result.put("msg", "该产品没找到对应的sku或者对个sku, 亲检查~");
            return result;
        }
        SupplierProduct supplierProduct = supplierProducts.get(0);

        //查询supplierPrice
        List<SupplierProductPrice> supplierProductPrices = this.supplierProductPriceService.queryAll(new SupplierProductPrice() {{
            setSupplierProductId(supplierProduct.getId());
        }});
        if (supplierProductPrices.size() > 1 || supplierProductPrices.size() == 0) {
            result.put("code", "4000");
            result.put("msg", "该产品没找到对应的价格或者多个价格, 亲检查~");
            return result;
        }
        SupplierProductPrice supplierProductPrice = supplierProductPrices.get(0);

        //查询图片
        List<SupplierGoodsPictureList> supplierGoodsPictureListList = this.supplierGoodsPictureListService.queryAll(new SupplierGoodsPictureList() {{
            setGid(supplierGood.getId());
        }});
        StringBuilder sb = new StringBuilder();//拼接图片地址
        for (int i = 0; i < supplierGoodsPictureListList.size(); i++) {
            sb.append(supplierGoodsPictureListList.get(i).getImagePath());
            if (i != supplierGoodsPictureListList.size() - 2) {
                sb.append(",");
            }
        }
        String images = sb.toString();
        //私有规格
        speMap.put("productId", supplierGood.getBrandid());
        speMap.put("goodsId", supplierProduct.getGoodsId());
        speMap.put("cooperatePrice", Double.valueOf(supplierProductPrice.getCooperateprice() / 100.0d));
        speMap.put("salePrice", Double.valueOf(supplierProductPrice.getSaleprice() / 100.0d));
        speMap.put("goodsDesc", supplierGood.getGoodsDesc());
        speMap.put("inventooryNum", supplierProduct.getInventoryNum());
        speMap.put("goodDescType", supplierGood.getGoodsDescType());
        speMap.put("images", images);

        Map<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("comonList", comonListMap);
        stringObjectHashMap.put("speList", speMap);
        result.put("code", "10000");
        result.put("data", stringObjectHashMap);

        return result;
    }

    /**
     * 批量删除
     */
    @Transactional
    @Override
    public Map<String, Object> delList(Map<String, Object> params) {


        Map<String, Object> res = new HashMap<>();
        Map<String, Object> result = new HashMap<>();
        if (CheckNullUtils.isNull(String.valueOf(params.get("ids"))) || String.valueOf(params.get("ids")).equals("[]")) {
            result.put("msg", "删除失败,您并没有选中任何");
            result.put("code", "5000");
            return result;
        }
        String ids = String.valueOf(params.get("ids"));
        Boolean flag = false;

        String substring = ids.substring(1, ids.length() - 1);
        String[] split = substring.split(",");
        for (String o : split) {
            Map<String, Object> parse = JSONObject.parseObject(o);
            Map<String, Object> map = deleteProductById(parse);
            if (CheckNullUtils.isNull(String.valueOf(map.get("msg")))) {
                res.put("data", "删除失败");
                res.put("msg", "删除失败");
                res.put("code", "5000");
                return res;
            }
            if (map.get("msg").equals("删除成功")) {
                result.put("code", "1");
            }
        }
        Set<String> strings = result.keySet();
        for (String string : strings) {
            if (result.get(string).equals("1")) {
                flag = true;
            }
        }
        if (flag) {
            res.put("data", "删除成功");
            res.put("code", "10000");
        } else {
            res.put("data", "删除失败");
            res.put("code", "5000");
        }

        return res;
    }

    /**
     * 商品的所有分类
     */
    @Override
    public Map<String, Object> getAllProductType(Map<String, Object> params) {

        Map<String, Object> result = new HashMap<>();

        List<ProductType> productTypes = this.productTypeService.queryLikeAll(new ProductType() {{
            setTypeName("");
        }});
        result.put("productTypes", productTypes);

        return result;
    }

    /**
     * 产品的推送状态
     */
    @Override
    public Map<String, Object> getPushStatus(Map<String, Object> params) {

        Map<String, Object> result = new HashMap<>();

        Map<String, Object> map1 = new HashMap<>();
        map1.put("num", "0");
        map1.put("pushStatus", "不推送");

        Map<String, Object> map2 = new HashMap<>();
        map2.put("num", "1");
        map2.put("pushStatus", "待推送");

        Map<String, Object> map3 = new HashMap<>();
        map3.put("num", "2");
        map3.put("pushStatus", "推送成功");

        Map<String, Object> map4 = new HashMap<>();
        map4.put("num", "3");
        map4.put("pushStatus", "推送失败");

        ArrayList<Object> pushStatus = new ArrayList<>();

        pushStatus.add(map1);
        pushStatus.add(map2);
        pushStatus.add(map3);
        pushStatus.add(map4);

        result.put("pushStatus", pushStatus);

        return result;
    }

    /**
     * 商品新增最终版
     */
    @Transactional
    @Override
    public Map<String, Object> saveGoods(Map<String, Object> params) {

        Map<String, Object> result = null;

        result = new HashMap<>();
        if (CheckNullUtils.isNull(String.valueOf(params.get("goodsList")))) {
            result.put("msg", "error~！没有接收到spu通用规格");
            result.put("code", "5000");
            result.put("data", "");
            return result;
        }
        if (CheckNullUtils.isNull(String.valueOf(params.get("skuDetails")))) {
            result.put("msg", "error~！没有接收到sku私有规格");
            result.put("code", "5000");
            result.put("data", "");
            return result;
        }


        String skuDetails2 = String.valueOf(params.get("skuDetails"));
        List<Map<String, Object>> list2 = (List<Map<String, Object>>) JSONObject.parse(skuDetails2);
        if (list2.size() == 0) {

            result.put("msg", "error~！请保存好2个弹框内容,规格需重置新增");
            result.put("code", "5000");
            result.put("data", "");
            return result;
        }
        ArrayList<String> productIdListss = new ArrayList<>();
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");//正整数
        Pattern pattern2 = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$"); // 判断小数点后2位的数字的正则表达式

        int singlePicNum = 1;
        for (Map<String, Object> skuDetailMap : list2) {
            String cooperatePrice1c = String.valueOf(skuDetailMap.get("cooperatePrice")); //进价
            String salePrice1c = String.valueOf(skuDetailMap.get("salePrice")); //售价
            String imageSkuUrl2c = String.valueOf(skuDetailMap.get("imageSkuUrl")); //商品图一张
            String productIdc = String.valueOf(skuDetailMap.get("productId")); //产品id
            String inventoryNumc = String.valueOf(skuDetailMap.get("inventoryNum")); //库存
            String storeIdc = String.valueOf(skuDetailMap.get("storeId")); //店铺id
            String inventoryIdc = String.valueOf(skuDetailMap.get("inventoryId")); //库存id
            productIdListss.add(productIdc);
            /*
             * 判断是否为整数
             * @param str 传入的字符串
             * @return 是整数返回true,否则返回false
             */

            if (CheckNullUtils.isNull(cooperatePrice1c) || CheckNullUtils.isNull(salePrice1c) || CheckNullUtils.isNull(inventoryNumc) || CheckNullUtils.isNull(productIdc)) {
                result.put("msg", "error~！sku  库存 产品id 需要填写");
                result.put("code", "5000");
                result.put("data", "");
                return result;
            }

            if (!pattern.matcher(productIdc).matches() || !pattern.matcher(inventoryNumc).matches()) {
                result.put("msg", "error~！sku 的id 库存等~需要填写正整数");
                result.put("code", "5000");
                result.put("data", "");
                return result;
            }

            if (!pattern2.matcher(cooperatePrice1c).matches() || !pattern2.matcher(salePrice1c).matches()) {
                result.put("msg", "error~！进价 ~售价只能填写2位小数的正整数");
                result.put("code", "5000");
                result.put("data", "");
                return result;
            }


            if (!CheckNullUtils.isNull(storeIdc)) {
                if (!pattern.matcher(storeIdc).matches()) {
                    result.put("msg", "error~！sku 的id 库存等~需要填写正整数");
                    result.put("code", "5000");
                    result.put("data", "");
                    return result;
                }
            }
            if (!CheckNullUtils.isNull(inventoryIdc)) {
                if (!pattern.matcher(inventoryIdc).matches()) {
                    result.put("msg", "error~！sku 的id 库存等~需要填写正整数");
                    result.put("code", "5000");
                    result.put("data", "");
                    return result;
                }
            }


            if (Double.valueOf(salePrice1c) < Double.valueOf(cooperatePrice1c)) {
                result.put("msg", "error~！进价低于售价");
                result.put("code", "5000");
                result.put("data", "");
                return result;
            }

            if (CheckNullUtils.isNull(imageSkuUrl2c.substring(1, imageSkuUrl2c.length() - 1))) {
                result.put("msg", "error~！第" + singlePicNum + "行单图没收到");
                result.put("code", "5000");
                result.put("data", "");
                return result;
            }
            singlePicNum++;

        }


      /*  for (int i = 0; i < productIdListss.size(); i++) {
            for (int j = 1; j < productIdListss.size(); j++) {
                if (productIdListss.get(j).equals(productIdListss.get(i))) {
                    result.put("msg", "error~！产品id冲突了");
                    result.put("code", "5000");
                    result.put("data", "");
                    return result;
                }
            }
        }*/
        HashSet<String> strings = new HashSet<>();

        productIdListss.forEach(productId -> {
            strings.add(productId);
        });
        if (strings.size() < productIdListss.size()) {
            result.put("msg", "error~！产品id冲突了");
            result.put("code", "5000");
            result.put("data", "");
            return result;
        }


        //运费0
        int freight = 0;
        int addGoods = 0;
        int addPicture = 0;
        int addPrice = 0;
        int addProduct = 0;
        //spu
        Map<String, Object> spuMaps = JSONObject.parseObject(String.valueOf(params.get("goodsList")));
        String name = String.valueOf(spuMaps.get("name")); //商品名字
        String brandNameCn = String.valueOf(spuMaps.get("brandNameCn")); //品牌中文名称
        String brandNameEn = String.valueOf(spuMaps.get("brandNameEn")); //品牌英文名称
        String supplierFullName = String.valueOf(spuMaps.get("supplierFullName")); //供应商全称
        String supplierRemark = String.valueOf(spuMaps.get("supplierRemark")); //供应商描述
        String goodNatureType = String.valueOf(spuMaps.get("goodNatureType")); //产品类别  实物虚拟
        String brandId = String.valueOf(spuMaps.get("brandId")); //品牌id
        String categoryParentName = String.valueOf(spuMaps.get("categoryParentName")); //分类
        String goodsDesc = String.valueOf(spuMaps.get("goodsDesc")); //商品描述
        String imageUrlTravel = String.valueOf(spuMaps.get("imageUrlTravel")); //轮播图
        String imageUrlDetail = String.valueOf(spuMaps.get("imageUrlDetail")); //详情图

        List<Supplier> suppliers = this.supplierService.queryAll(new Supplier() {{
            setFullName(supplierFullName);
        }});
        if (suppliers.size() > 1 || suppliers.size() < 0) {
            result.put("msg", "error~！供应商没查到或者供应商存在多个");
            result.put("data", "");
            result.put("code", "5000");
            return result;
        }
        if (CheckNullUtils.isNull(name) || CheckNullUtils.isNull(brandNameCn) || CheckNullUtils.isNull(brandId) || CheckNullUtils.isNull(goodsDesc) || supplierFullName.equals("直接选择或搜索") || categoryParentName.equals("直接选择或搜索")) {
            result.put("msg", "error~！spu 名字 品牌id 商品描述详 供应商 分类需要填写");
            result.put("code", "5000");
            result.put("data", "");
            return result;
        }
        //有id删除->新增  没id直接新增
        if (!CheckNullUtils.isNull(String.valueOf(params.get("id")))) {
            Map<String, Object> map = this.deleteProductById(new HashMap<String, Object>() {{
                put("id", params.get("id"));
            }});
            if (!map.get("msg").equals("删除成功")) {
                result.put("msg", "error~！更新失败~请检查~");
                result.put("code", "5000");
                result.put("data", "");
                return result;
            }
        }
        List<SupplierGoods> supplierGoods2 = this.supplierGoodsService.queryAll(new SupplierGoods() {{
            setBrandid(Long.valueOf(brandId));
        }});
        if (supplierGoods2.size() > 0) {
            result.put("msg", "error~！该供应商下面的品牌id、已经存在 注意填写");
            result.put("data", "");
            result.put("code", "5000");
            return result;
        }


        //todo 保存supplierGoods
        try {
            addGoods = this.supplierGoodsService.add(new SupplierGoods() {{
                setGoodNatureType(Integer.valueOf(goodNatureType));
                setBrandid(Long.valueOf(brandId));
                setSupplierName(supplierFullName);
                setBrandnamecn(brandNameCn);
                setBrandnameen(brandNameEn);
                setCategoryParentName(categoryParentName);
                setGoodsDescType("pic");
                setGoodsDesc(goodsDesc);
                setCreateTime(new Date());
                setLastUpdateTime(new Date());
                setSupplierGoodsId(brandId);
                setName(name);
                setSupplierId(Integer.valueOf(suppliers.get(0).getSupplierSn()));
                setSpecificationsString("");
                setSupplierRemark(supplierRemark);
            }}, false);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }


        List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryAll(new SupplierGoods() {{
            setName(name);
            setBrandid(Long.valueOf(brandId));
        }});
        SupplierGoods supplierGoods1 = supplierGoods.get(0);

        //保存图片 //todo 轮播
        try {
            if (!CheckNullUtils.isNull(imageUrlTravel)) {
                String imageUrlTravelList = imageUrlTravel.substring(1, imageUrlTravel.length() - 1);
                String[] lunboWYH = imageUrlTravelList.split(",");
                for (String s : lunboWYH) {
                    String imageSigle1 = s.substring(1, s.length() - 1);
                    addPicture = this.supplierGoodsPictureListService.add(new SupplierGoodsPictureList() {{
                        setGid(supplierGoods1.getId());
                        setWidth(200);
                        setHeight(200);
                        setImageType(1);
                        setImageOrder(0);
                        setImagePath(imageSigle1);
                        setGoodsId(brandId);
                    }}, false);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //todo 详情图
        try {
            if (!CheckNullUtils.isNull(imageUrlDetail)) {
                String imageUrlDetailList = imageUrlDetail.substring(1, imageUrlDetail.length() - 1);
                String[] detailWYH = imageUrlDetailList.split(",");
                for (String s : detailWYH) {
                    String imageSigle = s.substring(1, s.length() - 1);
                    addPicture = this.supplierGoodsPictureListService.add(new SupplierGoodsPictureList() {{
                        setGid(supplierGoods1.getId());
                        setWidth(200);
                        setHeight(200);
                        setImageType(2);
                        setImageOrder(0);
                        setImagePath(imageSigle);
                        setGoodsId(brandId);
                    }}, false);
                }
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        List<Map<String, Object>> mapLists = null;
        //skuDetails
        String skuDetails = String.valueOf(params.get("skuDetails"));
        List<Map<String, Object>> list = (List<Map<String, Object>>) JSONObject.parse(skuDetails);
        for (Map<String, Object> skuDetailMap : list) {
            String isHax = String.valueOf(skuDetailMap.get("isHax")); //是否含税
            String cooperatePrice1 = String.valueOf(skuDetailMap.get("cooperatePrice")); //进价
            String salePrice1 = String.valueOf(skuDetailMap.get("salePrice")); //售价
            String inventoryNum = String.valueOf(skuDetailMap.get("inventoryNum")); //库存
            String pushStatus = String.valueOf(skuDetailMap.get("pushStatus")); //推送状态
            String storeId = String.valueOf(skuDetailMap.get("storeId")); //店铺id
            String inventoryId = String.valueOf(skuDetailMap.get("inventoryId")); //库存id
            String productName = String.valueOf(skuDetailMap.get("productName")); //产品名字
            String productId = String.valueOf(skuDetailMap.get("productId")); //产品id
            String goodsId = String.valueOf(skuDetailMap.get("goodsId")); //商品编码
            String imageSkuUrl = String.valueOf(skuDetailMap.get("imageSkuUrl")); //商品图一张
            String skuSpes = String.valueOf(skuDetailMap.get("spe")); //规格值数组


            int cooperatePrice = getSavePrice(cooperatePrice1);
            int salePrice = getSavePrice(salePrice1);

            mapLists = (List<Map<String, Object>>) JSONObject.parse(skuSpes);
            ArrayList<Object> objects = new ArrayList<>();
            for (Map<String, Object> mapList : mapLists) {
                Map<String, Object> stringObjectHashMap = new HashMap<>();
                String key = String.valueOf(mapList.get("selectDataOne"));
                String value = String.valueOf(mapList.get("selectDataTwo"));
                if (CheckNullUtils.isNull(key) || CheckNullUtils.isNull(value)) {
                    continue;
                }
                stringObjectHashMap.put(key, value);
                objects.add(stringObjectHashMap);
            }
            String speString = JSONObject.toJSONString(objects);//todo

                /*
               *
               "spe":[
                        {"selectDataOne":"颜色","selectDataTwo":"黑色"},
                        {"selectDataOne":"尺寸","selectDataTwo":"17"},
                    ]
                    */
            //规格添加到product_attribute表

            List<ProductAttribute> productAttributes = this.productAttributeService.queryAll(new ProductAttribute() {{
                setProductId(Long.valueOf(productId));
            }});
            for (ProductAttribute productAttribute : productAttributes) {
                this.productAttributeService.remove(productAttribute.getId());
            }


            this.productAttributeService.remove(Long.valueOf(productId));


            for (Map<String, Object> map : mapLists) {
                String selectDataOne = String.valueOf(map.get("selectDataOne"));
                String selectDataTwo = String.valueOf(map.get("selectDataTwo"));
                List<ProAttribute> proAttributes = this.proAttributeService.queryAll(new ProAttribute() {{
                    setProductAttributeName(selectDataOne);
                }});
                if (proAttributes.size() == 0) {

                    throw new RuntimeException("该规格数据库没查到");
                }
                Long id = proAttributes.get(0).getId();
                this.productAttributeService.add(new ProductAttribute() {{
                    setProductId(Long.valueOf(productId));
                    setAttributeId(id);
                    setAttributeName(selectDataOne);
                    setAttributeValue(selectDataTwo);
                    setCreateTime(new Date());
                }}, false);

            }


            //todo 保存sku
            try {
                addProduct = this.supplierProductService.add(new SupplierProduct() {{
                    setProductInventoryId(inventoryId);
                    setStoreId(storeId);
                    setProductName(productName);
                    setGid(supplierGoods1.getId());
                    setSpecificationsString(speString);
                    setProductId(productId);
                    setProductImagePath(imageSkuUrl.substring(1, imageSkuUrl.length() - 1));
                    setHastax(Integer.valueOf(isHax));
                    setPushStatus(Integer.valueOf(pushStatus));
                    setIsImgCompression(0);
                    setInventoryNum(Integer.valueOf(inventoryNum));
                    setIsPerfect("Y");
                    setGoodsId(goodsId);
                }}, false);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(new SupplierProduct() {{
                setGoodsId(goodsId);
                setProductId(productId);
                setProductName(productName);
            }});
            //todo 保存价格

            try {
                for (SupplierProduct supplierProduct : supplierProducts) {
                    addPrice = this.supplierProductPriceService.add(new SupplierProductPrice() {{
                        setSupplierProductId(supplierProduct.getId());
                        if (isHax.equals("0")) {
                            setCooperateprice(cooperatePrice);
                            setTaxcooperateprice(0);
                        } else {
                            setTaxcooperateprice(cooperatePrice);
                            setCooperateprice(0);
                        }
                        setSaleprice(salePrice);
                        int private_cost_price = cooperatePrice + freight;
                        // 求差价
                        int diffPrice = (salePrice + freight) - cooperatePrice;
                        if (diffPrice < 0) {
                            System.out.println("严重警告 ,出现负数................................... 产品SKU ID : " + productId);
                        }
                        int step = diffPrice / 4; // 四个等级，每级的差价
                        setMoneyPrice(salePrice);
                        setLeve1Price(private_cost_price + step + step + step);
                        setLeve2Price(private_cost_price + step + step);
                        setLeve3Price(private_cost_price + step);
                        setLeve4Price(private_cost_price);
                        setUnionCostPrice(private_cost_price);
                        setDefaultFreight(freight);
                    }}, false);
                    if (addPrice != 1) {
                        throw new RuntimeException();
                    }
                }
            } catch (RuntimeException e) {
                e.printStackTrace();
            }
        }

       /*
       *
       "spe":[
				{"selectDataOne":"颜色","selectDataTwo":"黑色"},
				{"selectDataOne":"尺寸","selectDataTwo":"17"},
				{"selectDataOne":"颜色","selectDataTwo":"黑色"},
				{"selectDataOne":"尺寸","selectDataTwo":"17"}
			]
			*/
        List<Map<String, Object>> listC = (List<Map<String, Object>>) JSONObject.parse(String.valueOf(mapLists));
        ArrayList<Object> outSpe = new ArrayList<>();

        HashSet<String> keySets = new HashSet<>();
        for (Map<String, Object> object : listC) {
            String selectDataOne = String.valueOf(object.get("selectDataOne"));
            keySets.add(selectDataOne);//所有key
        }
        for (String keySet : keySets) {
            Map<String, Object> thirdMap = new HashMap<>();
            thirdMap.put("name", keySet);
            ArrayList<Object> valueLists = new ArrayList<>();
            Map<String, Object> valueMap = new HashMap<>();
            for (Map<String, Object> object : listC) {
                String selectDataOne = String.valueOf(object.get("selectDataOne").toString());
                if (selectDataOne.equals(keySet)) {
                    valueMap.put(selectDataOne, object.get("selectDataTwo").toString());
                    valueLists.add(valueMap);
                }
            }
            thirdMap.put("value", valueLists);
            outSpe.add(thirdMap);
        }

        supplierGoods1.setSpecificationsString(JSONObject.toJSONString(outSpe));
        int modify = this.supplierGoodsService.modify(supplierGoods1, false);

        if (addGoods == 1 & addPicture == 1 && addPrice == 1 && addProduct == 1 && modify == 1) {
            result.put("data", "保存成功");
            result.put("msg", "保存成功");
            result.put("code", "10000");
            return result;
        }
        result.put("data", "保存成功");
        result.put("msg", "保存成功");
        result.put("code", "10000");
        return result;

    }

    /**
     * 前台回显数据最终版本
     */
    @Override
    public Map<String, Object> backShow(String id) {

        Map<String, Object> result = new HashMap<>();

        List<SupplierGoods> supplierGoodss = this.supplierGoodsService.queryAll(new SupplierGoods() {{
            setId(Long.valueOf(id));
        }});
        if (supplierGoodss.size() > 1 || supplierGoodss.size() == 0) {
            result.put("data", "");
            result.put("msg", "id有问题~刷新试试");
            result.put("code", "5000");
            return result;
        }
        SupplierGoods supplierGoods = supplierGoodss.get(0);

        //轮播图
        List<SupplierGoodsPictureList> travelImages = this.supplierGoodsPictureListService.queryAll(new SupplierGoodsPictureList() {{
            setGid(supplierGoods.getId());
            setImageType(1);
        }});
        ArrayList<Object> travelImagess = new ArrayList<>();
        for (SupplierGoodsPictureList travelImage : travelImages) {
            Map<String, Object> stringObjectHashMap = new HashMap<>();
            stringObjectHashMap.put("travelUrl", travelImage);
            travelImagess.add(stringObjectHashMap);
        }

        //详情图
        List<SupplierGoodsPictureList> detailsImages = this.supplierGoodsPictureListService.queryAll(new SupplierGoodsPictureList() {{
            setGid(supplierGoods.getId());
            setImageType(2);
        }});
        ArrayList<Object> detailsImagess = new ArrayList<>();
        for (SupplierGoodsPictureList detailsImage : detailsImages) {
            Map<String, Object> stringObjectHashMap1 = new HashMap<>();
            stringObjectHashMap1.put("detailsUrl", detailsImage);
            detailsImagess.add(stringObjectHashMap1);
        }

        List<Supplier> suppliers = this.supplierService.queryAll(new Supplier() {{
            setFullName(supplierGoods.getSupplierName());
            //  setSupplierSn(String.valueOf(supplierGoods.getSupplierId()));
        }});
        Supplier supplier = suppliers.get(0);
        Long supplierNameId = supplier.getId();

        List<ProductType> productTypes = this.productTypeService.queryAll(new ProductType() {{
            setTypeName(supplierGoods.getCategoryParentName());
        }});
        Long categoryParentNameId = productTypes.get(0).getId();

        Map<String, Object> goodsListMap = new HashMap<String, Object>() {{
            put("name", supplierGoods.getName());
            put("brandNameCn", supplierGoods.getBrandnamecn());
            put("brandNameEn", supplierGoods.getBrandnameen());
            put("supplierFullName", supplierGoods.getSupplierName());
            put("supplierNameId", supplierNameId);
            put("supplierId", supplierGoods.getSupplierId());
            put("supplierRemark", supplierGoods.getSupplierRemark());
            put("brandId", supplierGoods.getBrandid());
            put("categoryParentName", supplierGoods.getCategoryParentName());
            put("categoryParentNameId", categoryParentNameId);
            put("goodsDesc", supplierGoods.getGoodsDesc());
            put("goodNatureType", supplierGoods.getGoodNatureType());
            put("imageUrlTravel", travelImagess);
            put("imageUrlDetail", detailsImagess);
        }};

        //skuDetails
        ArrayList<Object> skuDetails = new ArrayList<>();

        List<SupplierProduct> supplierProducts = this.supplierProductService.queryAll(new SupplierProduct() {{
            setGid(supplierGoods.getId());
            //  setProductName(supplierGoods.getName());
        }});
        if (CollectionUtils.isEmpty(supplierProducts)) {
            result.put("data", "");
            result.put("msg", "该商品没找到对应的产品~刷新试试");
            result.put("code", "5000");
            return result;
        }
        for (SupplierProduct supplierProduct : supplierProducts) {
            List<SupplierProductPrice> supplierProductPrices = this.supplierProductPriceService.queryAll(new SupplierProductPrice() {{
                setSupplierProductId(supplierProduct.getId());
            }});
            if (supplierProductPrices.size() > 1 || supplierProductPrices.size() == 0) {
                result.put("data", "");
                result.put("msg", "该产品没找到对应的价格 或者多个价格~刷新试试");
                result.put("code", "5000");
                return result;
            }
            SupplierProductPrice supplierProductPrice = supplierProductPrices.get(0);

           /* for (SupplierProductPrice productPrice : supplierProductPrices) {

            }*/

            Map<String, Object> skuDetailsSingle = new HashMap<String, Object>() {{
                if (supplierProductPrice.getCooperateprice() == 0) {
                    put("cooperatePrice", Double.valueOf(supplierProductPrice.getTaxcooperateprice()) / 100.0);
                    put("isHax", "1");
                } else {
                    put("cooperatePrice", supplierProductPrice.getCooperateprice() / 100.0);
                    put("isHax", "0");
                }
                put("salePrice", Double.valueOf(supplierProductPrice.getSaleprice()) / 100.0);
                put("inventoryNum", supplierProduct.getInventoryNum());
                put("pushStatus", supplierProduct.getPushStatus());

                if (supplierProduct.getStoreId() == null) {
                    put("storeId", "''");
                } else {
                    put("storeId", supplierProduct.getStoreId());
                }
                if (supplierProduct.getProductInventoryId() == null) {
                    put("productInventoryId", "''");
                } else {
                    put("productInventoryId", supplierProduct.getProductInventoryId());
                }


                put("productName", supplierProduct.getProductName());
                put("imageSkuUrl", supplierProduct.getProductImagePath());
                put("productId", supplierProduct.getProductId());
                put("goodsId", supplierProduct.getGoodsId());
                //规格参数对应id封装
                List<Map<String, Object>> list = (List<Map<String, Object>>) JSONObject.parse(supplierProduct.getSpecificationsString());
                String selectDataTwo = null;
                String selectDataOne = null;
                for (Map<String, Object> map : list) {
                    Set<String> keySet = map.keySet();
                    for (String s : keySet) {
                        selectDataOne = s;
                    }
                    Collection<Object> values = map.values();
                    for (Object value : values) {
                        selectDataTwo = String.valueOf(value);
                    }
                    String finalSelectDataTwo = selectDataTwo;
                    String finalSelectDataOne = selectDataOne;
                    List<AttributeValue> attributeValues = attributeValueService.queryAll(new AttributeValue() {{
                        setAttributeValue(finalSelectDataTwo);
                        setAttributeName(finalSelectDataOne);
                    }});
                    Long selectDataTwoId = -1L;
                    if (attributeValues.size() != 0) {
                        selectDataTwoId = attributeValues.get(0).getId();  //规格2id
                    }

                    map.put("selectDataTwoId", selectDataTwoId);
                    map.put("selectDataTwo", finalSelectDataTwo);
                    Map<String, Object> attributeValueMap = attributeValueService.queryAllName();
                    System.out.println(JSONObject.toJSONString(attributeValueMap));
                    List<Map<String, Object>> attributeValueList = (List<Map<String, Object>>) JSONObject.parse(JSONObject.toJSONString(attributeValueMap.get("data")));
                    for (Map<String, Object> stringObjectMap : attributeValueList) {
                        String attributeName = String.valueOf(stringObjectMap.get("productAttributeName"));
                        if (attributeName.equals(finalSelectDataOne)) {
                            map.put("selectDataOneId", stringObjectMap.get("id"));
                            map.put("selectDataOne", finalSelectDataOne);
                        }
                    }
                }
                put("spe", list);
            }};
            skuDetails.add(skuDetailsSingle);
        }

        Map<String, Object> resultBefore = new HashMap<>();

        resultBefore.put("goodsList", goodsListMap);
        resultBefore.put("skuDetails", skuDetails);
        result.put("code", "10000");
        result.put("msg", "ok");
        result.put("data", resultBefore);

        return result;
    }

    /**
     * productId查属性
     */
    @Override
    public Map<String, Object> productIdFindAttr(String productId) {
        Map<String, Object> resultMap = new HashMap<>();

        List<ProductAttribute> productAttributes = this.productAttributeService.queryAll(new ProductAttribute() {{
            setProductId(Long.valueOf(productId));
        }});
        resultMap.put("data", productAttributes);
        resultMap.put("code", 10000);
        resultMap.put("msg", "查询成功~");

        return resultMap;
    }

    /**
     * 所有的spuName
     */
    @Override
    public Map<String, Object> queryAllSpuName() {

        List<SupplierGoods> supplierGoods = this.supplierGoodsService.queryLikeAll(new SupplierGoods() {{
            setName("");
        }});
        Map<String, Object> relust = new HashMap<>();
        relust.put("data", supplierGoods);
        relust.put("code", 10000);
        relust.put("msg", "查询成功~");
        return relust;
    }
}